/**********************************************************************
 * Filename: Continente.java
 * Created: 2012/04/30
 * @author Fernando Brito e Abreu
 **********************************************************************/
package org.quasar.CopaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Continente {
	public static Set<Continente> allInstances = new HashSet<Continente>();

	private String nome;

	/**********************************************************************
	 * Default constructor
	 **********************************************************************/
	public Continente() {
		allInstances.add(this);
	}

	/**********************************************************************
	 * Parameterized constructor
	 * 
	 * @param nome
	 *            the nome to initialize
	 **********************************************************************/
	public Continente(String nome) {
		this.nome = nome;
		allInstances.add(this);
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the nome of the continente
	 **********************************************************************/
	public String getNome() {
		return nome;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param nome
	 *            the nome to set
	 **********************************************************************/
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**********************************************************************
	 * ONE2MANY getter for Continente[1] <-> Pais[*]
	 * 
	 * @return the paises of the continente
	 **********************************************************************/
	public Set<Pais> paises() {
		Set<Pais> result = new HashSet<Pais>();
		for (Pais x : Pais.allInstances)
			if (x.continente() == this)
				result.add(x);
		return result;
	}

	/**********************************************************************
	 * ONE2MANY setter for Continente[1] <-> Pais[*]
	 * 
	 * @param paises
	 *            the paises to set
	 **********************************************************************/
	public void setPaises(Set<Pais> paises) {
		for (Pais x : paises)
			x.setContinente(this);
	}

	/**********************************************************************
	 * User-defined operation specified in SOIL/OCL
	 * 
	 * @param nome
	 *            the nome to set
	 **********************************************************************/
	public void inicializa(String nome) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	/**********************************************************************
	 * Object serializer
	 **********************************************************************/
	public String toString() {
		return "Continente [nome=" + nome + "]\n";
	}

}
